Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ported TraktKit to tvOS #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Michelasso
Copy link

Converted frameworks to Universal frameworks
Added test for tvOS and macOS

I have also changed a couple of other things. For example I couldn't fetch the avatars, the "user" structure (If I remember correctly. I had actually changed it nearly a year ago and ported the change to this new fork). needed to be more nested.

Also I renamed "set" to "setOauth2RedirectURL", just deprecating the old "set". But I can revert it if you don't like the new name, it just made more sense to me.

Now with Universal Frameworks one just need to add

import TraktKit

no matter the OS type. Thanks to this now all tests are common for iOS, tvOS and macOS (same source files, I just added the targets) and most important, they all succeeded. Also the prototype app I was developing compiled and run without any issue (and using all my modifications).

This is more or less the same work I did for TheMovieDatabaseSwiftWrapper, which has been merged months ago.

Last thing: I had also modified "getUserWatchedHistory" adding the pagination, but when I ported my old function it gave an error compiling. Also I am a bit lost, because I see there is a "getHistory". Are they any different (I have checked the Trakt TV APIs and I must have missed "getHistory")? Should I make a new pull request (after this one) to add the pagination in "getUserWatchedHistory"?

Converted frameworks to Universal frameworks
Added test for tvOS and macOS
@Michelasso
Copy link
Author

Please wait to merge. I have a couple of issues coming from bad copy&paste. Also I am cleaning it a bit from my comments

@@ -40,7 +40,7 @@ public class MLKeychain {
let keychainQuery: [String: Any] = [
kSecClassValue: kSecClassGenericPasswordValue,
kSecAttrAccountValue: key,
kSecReturnDataValue: kCFBooleanTrue,
kSecReturnDataValue: kCFBooleanTrue!,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why I have been told by Xcode to fix this one. It was working a year ago I suppose?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to look into this some. I'd love to avoid any force unwraps.

@Michelasso
Copy link
Author

Ok, it should be fine, now. I forgot to mention that I also added the methods "getDeviceCode" and "getTokenFromDeviceCode", useful to login with a code (to insert via a web browser after authenticating).

All tests are working, just giving a warning because I deprecate "set()" as explained above.

Also it has been "ported" by Xcode to Swift 5.0 (Xcode made no changes to the source code).

Comment on lines +58 to +64
if #available(iOSApplicationExtension 11.3, *) {
#if DEBUG
print("[\(#function)] Security result error code is: \(String(SecCopyErrorMessageString(status, nil) ?? "UNKNOWN"))")
#endif
} else {
// Fallback on earlier versions
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

Comment on lines +120 to +130
public func setOauth2RedirectURL(withClientID: String, clientSecret secret: String, redirectURI: String, staging: Bool = false) {
self.clientID = withClientID
self.clientSecret = secret
self.redirectURI = redirectURI

self.staging = staging

self.baseURL = !staging ? "trakt.tv" : "staging.trakt.tv"
self.APIBaseURL = !staging ? "api.trakt.tv" : "api-staging.trakt.tv"
self.oauthURL = URL(string: "https://\(baseURL!)/oauth/authorize?response_type=code&client_id=\(withClientID)&redirect_uri=\(redirectURI)")
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be reverted. set could use a better signature but I'm iffy on setOauth2RedirectURL, this can be a different PR / change to the tvOS support.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem. I just wanted to give it a different name because "set" was a bit too generic.

Comment on lines +46 to +50
public var deviceCode: String?
public var userCode: String?
public var verificationURL: String?
public var timeInterval: TimeInterval?
public var expiresIn: TimeInterval?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to look into the API some more before I know if a struct would be better than the variables kept in this class. I would recommend adding more documentation from the Trakt API to define all of these.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had looked into that. I wasn't sure either. But I needed them to make the authorization functions working on tvOS.

@@ -16,13 +16,15 @@ public struct User: Codable {
public let name: String?
public let isVIP: Bool?
public let isVIPEP: Bool?
// public let ids: ID
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should be reverted, I just merged a PR that added support for this.

@@ -40,7 +40,7 @@ public class MLKeychain {
let keychainQuery: [String: Any] = [
kSecClassValue: kSecClassGenericPasswordValue,
kSecAttrAccountValue: key,
kSecReturnDataValue: kCFBooleanTrue,
kSecReturnDataValue: kCFBooleanTrue!,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to look into this some. I'd love to avoid any force unwraps.

}


let urlString = "https://\(baseURL!)/oauth/device/code"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid force unwrapping.

Comment on lines +288 to +294
if let deviceCodeDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: AnyObject] {

welf.deviceCode = deviceCodeDict["device_code"] as? String
welf.userCode = deviceCodeDict["user_code"] as? String
welf.verificationURL = deviceCodeDict["verification_url"] as? String
welf.timeInterval = deviceCodeDict["interval"] as? TimeInterval
welf.expiresIn = deviceCodeDict["expires_in"] as? TimeInterval
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think decoding into an object would be preferable to this old way of decoding JSON

return
}

let urlString = "https://\(baseURL!)/oauth/device/token"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force unwrap

Comment on lines +13 to +32
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
XCUIApplication().launch()

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() {
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this default code can be removed?

Copy link
Author

@Michelasso Michelasso Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't remember. Probably, I think I just added the tests for the two platforms, but I didn't really look at the code.

Comment on lines +14 to +32
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@MaxHasADHD
Copy link
Owner

Sorry for the wait on this. I became pretty burnt out. I'll try to be more active when I can.

@Michelasso
Copy link
Author

Yeah, I am pretty busy myself, now. Working online from home. Also I didn't touch the project for quite a long time. IB for tvOS went banana with Xcode 11.

So how does it work? Should I apply the changes requested and update?

@MaxHasADHD
Copy link
Owner

@Michelasso if you can, yes. Resolve the conflicts, and address comments. No rush though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants